# 列表，元组和字符串相互转化函数 - list(), tuple(), str()

# 将一个可迭代对象转化为列表:list
list1 = list("FishC")
print(list1)  # ['F', 'i', 's', 'h', 'C']

# 将元组转化为列表
list2 = list((1, 2, 3, 4, 5))
print(list2)  # [1, 2, 3, 4, 5

# 将一个可迭代对象转化为元组：tuple
tuple1 = tuple("FishC")
print(tuple1)  # ('F', 'i', 's', 'h', 'C')

tuple2 = tuple([1, 2, 3, 4])
print(tuple2)  # (1, 2, 3, 4)

# 将一个可迭代对象转化为字符串：str
str1 = str([1, 2, 3, 4, 5])
print(str1)  # '[1, 2, 3, 4, 5]
print(type(str1))  # <class 'str'>

str2 = str((1, 2, 3, 4, 5))
print(str2)  # '(1, 2, 3, 4, 5)'
print(type(str2))  # <class 'str'>

# min
s = [1, 1, 2, 3, 5]
print(min(s))  # [1, 2, 3, 4, 5]

t = "FishC"
print(max(t))  # s  -- 如果传入的是字符串，那么,min,max函数中比较的是字符串中字符的编码值

s = []
# print(min(s))  # ValueError: min() arg is an empty sequence
r = min(s, default='屁，啥都没有，怎么找到最小？')
print(r)  # 屁，啥都没有，怎么找到最小？

print(min(1, 2, 3, 0, 6))  # 0
print(max(1, 2, 3, 0, 6))  # 6

# len() 跟 sum()

# 2** 100 ：表示2的100次方
# print(len(range(2 ** 100)))  # OverflowError: Python int too large to convert to C ssize_t

s = [1, 0, 0, 8, 6]
print(sum(s))  # 15
print(sum(s, start=100))  # 115 start表示从100开始累加

# sorted 跟 reversed
s = [1, 0, 0, 8, 6]
r = sorted(s)
print(s)  # [1, 0, 0, 8, 6]
print(r)  # [0, 0, 1, 6, 8] 返回了一个全新的列表，原来的列表不受影响
s.sort()  # 在原来的列表上改
print(s)  # [0, 0, 1, 6, 8] 原列表被改变了

s = [1, 2, 3, 0, 6]
sorted_result = sorted(s, reverse=True)  # 把结果反转
print(sorted_result)  # [6, 3, 2, 1, 0]

t = ["FishC", "Apple", "Book", "Banana", "Pen"]
sorted_result2 = sorted(t)
print(sorted_result2)  # ['Apple', 'Banana', 'Book', 'FishC', 'Pen']

sorted_result3 = sorted(t, key=len)  # key 指定按照 len 函数的结果进行排序
print(sorted_result3)  # ['Pen', 'Book', 'FishC', 'Apple', 'Banana']

t.sort(key=len)
print(t)  # ['Pen', 'Book', 'FishC', 'Apple', 'Banana']

print(sorted("FishC"))  # ['C', 'F', 'h', 'i', 's']
print(sorted((1, 0, 0, 8, 6)))  # [0, 0, 1, 6, 8]

s = [1, 2, 5, 8, 0]
iterator1 = reversed(s)  # 得到一个反向的迭代器
print(iterator1)  # <list_reverseiterator object at 0x109cfb9a0>
# 把迭代器转化为列表
print(list(iterator1))  # [0, 8, 5, 2, 1]
s.reverse()
print(s)  # [0, 8, 5, 2, 1]

print(list(reversed("FishC")))  # ['C', 'h', 's', 'i', 'F']
print(list(reversed((1, 2, 5, 9, 3))))  # [3, 9, 5, 2, 1]
print(list(reversed(range(0, 10))))  # [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]
